﻿using System;
using System.Security.Principal;
using System.ServiceModel;
using System.Threading.Tasks;

namespace Tiscs.Practices.Web.Services
{
    /// <summary>
    /// 用户验证服务定义接口。
    /// </summary>
    /// <typeparam name="T">用户信息类的类型。</typeparam>
    [ServiceContract(Name = AuthenticationServiceResource.ServiceName, Namespace = AuthenticationServiceResource.ServiceNamespace)]
    public interface IAuthenticationService<T> where T : IPrincipal
    {
        /// <summary>
        /// 获取当前用户的用户信息。
        /// </summary>
        /// <returns>当前用户的用户信息。</returns>
        [OperationContract(
            Name = AuthenticationServiceResource.GetUserName,
            Action = AuthenticationServiceResource.GetUserAction,
            ReplyAction = AuthenticationServiceResource.GetUserReplyAction)]
        Task<T> GetUser();

        /// <summary>
        /// 用户登录。
        /// </summary>
        /// <param name="userName">用户名。</param>
        /// <param name="password">密码。</param>
        /// <param name="customCredential">自定义凭据。</param>
        /// <param name="isPersistent">是否持久登录。</param>
        /// <returns>当前用户的用户信息。</returns>
        [OperationContract(
            Name = AuthenticationServiceResource.SignInName,
            Action = AuthenticationServiceResource.SignInAction,
            ReplyAction = AuthenticationServiceResource.SignInReplyAction)]
        Task<T> SignIn(string userName, string password, string customCredential, bool isPersistent);

        /// <summary>
        /// 注销登录。
        /// </summary>
        /// <returns>当前用户的用户信息。</returns>
        [OperationContract(
            Name = AuthenticationServiceResource.SignOutName,
            Action = AuthenticationServiceResource.SignOutAction,
            ReplyAction = AuthenticationServiceResource.SignOutReplyAction)]
        Task<T> SignOut();

        /// <summary>
        /// 更新用户。
        /// </summary>
        /// <param name="user">要更新的用户信息。</param>
        [OperationContract(
            Name = AuthenticationServiceResource.UpdateUserName,
            Action = AuthenticationServiceResource.UpdateUserAction,
            ReplyAction = AuthenticationServiceResource.UpdateUserReplyAction)]
        Task UpdateUser(T user);
    }
}